home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AppleScript - The Beta Release
/
AppleScript - The Beta Release.iso
/
Goodies
/
AutoGuest
/
AutoGuest.c
< prev
next >
Wrap
Text File
|
1991-10-16
|
3KB
|
133 lines
/*
// Glue for the various AutoGuest patches
//
// by Greg Anderson, Paul Young and Michael Gough
*/
#include <Traps.h>
#include <Processes.h>
#include <PPCToolbox.h>
#include "AutoGuest.h"
/*
// Strangely enough, the PPC Dispatch trap isn't defined in any .h file
*/
#define _PPC 0xA0DD
/*----------------------------------------------------------------------
Install the PPC AutoGuest patch
This patch allows an application to start a session with a
remote computer without bringing up an authentication dialog
box if (& only if) it is possible to connect to said machine
as a guest
This function returns a longword which should be passed to
DeinstallPPCAutoGuest to remove the patch
----------------------------------------------------------------------*/
long InstallPPCAutoGuest()
{
extern void PPCAutoGuest();
extern void OldPPCAddress();
long oldPPCDispatch;
long newPPCDispatch;
long* modifyReturnAddress;
oldPPCDispatch = NGetTrapAddress(_PPC, OSTrap) ;
newPPCDispatch = (long)PPCAutoGuest;
if( oldPPCDispatch == newPPCDispatch )
return 0;
modifyReturnAddress = (long*) (OldPPCAddress);
*modifyReturnAddress = oldPPCDispatch;
NSetTrapAddress( newPPCDispatch, _PPC, OSTrap);
return oldPPCDispatch;
}
/*----------------------------------------------------------------------
Remove the PPC AutoGuest patch
The parameter should be the longword returned from
InstallPPCAutoGuest
----------------------------------------------------------------------*/
void DeinstallPPCAutoGuest( long oldPPCDispatch )
{
if( oldPPCDispatch )
NSetTrapAddress( oldPPCDispatch, _PPC, OSTrap);
}
/*----------------------------------------------------------------------
Install the 'No Interaction Allowed' Patch
This patch prevents the EPPC toolbox from returning a
'No User Interaction Allowed' error (-610) if your application
attempts to start a session while it is in the background.
----------------------------------------------------------------------*/
long InstallNoInteractionPatch()
{
extern void DisposePatch();
extern void OldDisposeAddress();
long oldDispose;
long newDispose;
long* modifyReturnAddress;
oldDispose = NGetTrapAddress(_DisposHandle, OSTrap) ;
newDispose = (long)DisposePatch;
if( oldDispose == newDispose )
return 0;
modifyReturnAddress = (long*) (OldDisposeAddress);
*modifyReturnAddress = oldDispose;
NSetTrapAddress( newDispose, _DisposHandle, OSTrap) ;
return oldDispose;
}
/*----------------------------------------------------------------------
Remove the 'No Interaction Allowed' Patch
The parameter should be the longword returned from
InstallPPCAutoGuest
----------------------------------------------------------------------*/
void DeinstallNoInteractionPatch( long oldDispose )
{
if( oldDispose )
NSetTrapAddress( oldDispose, _DisposHandle, OSTrap);
}
/*----------------------------------------------------------------------
This function returns 'true' if the current process is in the
foreground. It is used by the PPC Autoguest patch.
----------------------------------------------------------------------*/
Boolean InForeGround()
{
ProcessSerialNumber currentPSN;
ProcessSerialNumber forePSN;
Boolean isFore;
GetCurrentProcess( ¤tPSN );
GetFrontProcess( &forePSN );
SameProcess( ¤tPSN, &forePSN, &isFore );
return isFore;
}